using System.Collections;
using System.Collections.Generic;
using MyProject.Persona;
using UnityEngine;

public class JumpCheck : MonoBehaviour
{
    private float timer;

    private PlayerController _controller;
    public float Timer => timer;
    private bool jumpGrace;

    public JumpCheck(PlayerController controller, bool jumpGrace)
    {
        this._controller = controller;
        ResetTime();
        this.jumpGrace = jumpGrace;
    }

    public void ResetTime()
    {
        timer = 0;
    }

    public void UpdateJumpCheck()
    {
        if (_controller.physicsCheck.isGround)
        {
            timer = Constants.JumpGraceTime;
            _controller.jumpCount = 1;
            // _controller.canInputAdvance = false;
        }
        else
        {
            if (timer > 0)
            {
                timer -= Time.deltaTime;
            }
        }
        
    }

    public bool AllowJump()
    {
        return jumpGrace ? timer > 0 : _controller.physicsCheck.isGround;
    }
}
